﻿using Main.Extend;
using Main.Extend.Attributes;
using Microsoft.Extensions.Configuration;


namespace Main.Common
{
    /// <summary>
    /// 小程序基类
    /// </summary>
    [Provider, Inject]
    public class MiniProgram : BaseCommon
    {
        private string AppId;
        private string AppSecret;
        private string MiniOpenIdUrl = "https://api.weixin.qq.com/sns/jscode2session?appid={0}&secret={1}&js_code={2}&grant_type=authorization_code";
        private Dictionary<string, string> Result;

        public MiniProgram(IConfiguration configuration) : base(configuration)
        {
            AppId = _Config["MiniProgram:AppId"] ?? "";
            AppSecret = _Config["MiniProgram:AppSecret"] ?? "";
            Result = new Dictionary<string, string>();
            Result.Add("code", "fail");
            Result.Add("msg", "获取失败");
        }

        /// <summary>
        /// 获取小程序openId
        /// </summary>
        /// <param name="LoginCode"></param>
        /// <returns></returns>
        public Dictionary<string, string> GetMinOpenId(string LoginCode)
        {

            // 请求地址
            string Url = MiniOpenIdUrl.Format(AppId, AppSecret, LoginCode);


            // 在此调用请求来和获取你的小程序OpenId 并处理返回你的结果



            return Result;
        }

    }
}
